.Net Improve type safety: Return TRecord instead of object in ITextSearch.GetSearchResultsAsync#13318
Merged
markwallace-microsoft merged 1 commit intomicrosoft:feature-text-search-linqfrom Nov 3, 2025
Conversation
…rchResults<TRecord> - Change interface return type from KernelSearchResults<object> to KernelSearchResults<TRecord> - Update VectorStoreTextSearch implementation with new GetResultsAsTRecordAsync helper - Keep GetResultsAsRecordAsync for legacy ITextSearch interface backward compatibility - Update 3 unit tests to use strongly-typed DataModel instead of object Benefits: - Improved type safety - no more casting required - Better IntelliSense and developer experience - Zero breaking changes to legacy ITextSearch interface - All 19 unit tests pass This is Part 2.1 of the Issue microsoft#10456 multi-PR chain, refining the API .
westey-m
approved these changes
Oct 31, 2025
Author
|
Thanks for the review, @westey-m. @markwallace-microsoft, could we go ahead and merge this? Deployment passed and it's been approved. We need to get this into other PRs as well. Appreciate it! |
alzarei
added a commit
to alzarei/semantic-kernel
that referenced
this pull request
Nov 3, 2025
…ts<BingWebPage> per PR microsoft#13318 - Change ITextSearch<BingWebPage>.GetSearchResultsAsync to return KernelSearchResults<BingWebPage> instead of <object> - Add strongly-typed helper GetResultsAsBingWebPageAsync returning IAsyncEnumerable<BingWebPage> - Update tests to expect strongly-typed results (no manual casting needed) - Fix duplicate XML comment issue This aligns with PR microsoft#13318 interface type safety improvements and eliminates wasteful casting.
alzarei
added a commit
to alzarei/semantic-kernel
that referenced
this pull request
Nov 3, 2025
…Async Changes: - Update GoogleTextSearch.GetSearchResultsAsync to return KernelSearchResults<GoogleWebPage> instead of KernelSearchResults<object> - Remove wasteful .Cast<object>() call - Update test to use strongly-typed GoogleWebPage instead of casting from object Benefits: - Eliminates runtime casting overhead - Provides compile-time type safety - Improves IntelliSense for consumers This change aligns with PR microsoft#13318 interface fix that changed ITextSearch<TRecord>.GetSearchResultsAsync to return KernelSearchResults<TRecord>.
markwallace-microsoft
approved these changes
Nov 3, 2025
27c93be
into
microsoft:feature-text-search-linq
16 checks passed
This was referenced Nov 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR enhances the type safety of the
ITextSearch<TRecord>interface by changing theGetSearchResultsAsyncmethod to returnKernelSearchResults<TRecord>instead ofKernelSearchResults<object>. This improvement eliminates the need for manual casting and provides better IntelliSense support for consumers.Motivation and Context
The current implementation of
ITextSearch<TRecord>.GetSearchResultsAsyncreturnsKernelSearchResults<object>, which requires consumers to manually cast results to the expected type. This reduces type safety and degrades the developer experience by losing compile-time type checking and IntelliSense support.This change aligns the return type with the generic type parameter
TRecord, providing the expected strongly-typed results that users of a generic interface would anticipate.Changes Made
Interface (ITextSearch.cs)
ITextSearch<TRecord>.GetSearchResultsAsyncreturn type fromKernelSearchResults<object>toKernelSearchResults<TRecord>ITextSearchinterface (non-generic) remains unchanged, continuing to returnKernelSearchResults<object>for backward compatibilityImplementation (VectorStoreTextSearch.cs)
GetResultsAsTRecordAsynchelper method returningIAsyncEnumerable<TRecord>GetResultsAsRecordAsyncmethod for the legacy non-generic interfaceTests (VectorStoreTextSearchTests.cs)
DataModelorDataModelWithRawEmbeddinginstead ofobjectBreaking Changes
Interface Change (Experimental API):
ITextSearch<TRecord>.GetSearchResultsAsyncnow returnsKernelSearchResults<TRecord>instead ofKernelSearchResults<object>[Experimental("SKEXP0001")], indicating that breaking changes are expected during the preview periodITextSearchinterface (non-generic) is unaffected and maintains full backward compatibilityBenefits
Testing
Related Work
This PR is part of the Issue #10456 multi-PR chain for modernizing ITextSearch with LINQ-based filtering:
All PRs target the
feature-text-search-linqbranch for coordinated release.Migration Guide for Consumers
Before (Previous API)
After (Improved API)
Checklist